﻿<!-- jsp文件头和头部 -->
<!DOCTYPE html>
<html lang="en" style="background:#fff;">
<head>
    <base href="${basePath}">
	<#include "common/top.html" />
	<link type="text/css" rel="stylesheet" href="${basePath}plugins/zTree/3.5.1/zTreeStyle/zTreeStyle.css"/>
	<script type="text/javascript" src="${basePath}plugins/zTree/3.5.1/jquery.ztree.core.js"></script>
	<script type="text/javascript" src="${basePath}plugins/zTree/3.5.1/jquery.ztree.excheck.js"></script>
</head>
<body style="background:#fff;">
<br>
	<div class="layui-elem-field" style="overflow: auto;width: 40%;float: left;height: 465px;margin-left: 16px;">
		<ul id="tree" class="ztree"></ul>
	</div>
	<form class="layui-form layui-form-pamel" modelAttribute="menu" name="form1" id="form1"  method="post" style="float: left;">
		<div class="">

		<input type="hidden" name="menuId" id="menuId" value="${sysMenu.menuId}"/>
		<div class="layui-form-item layui-form-item-dialog-menu">
			<label class="layui-form-label"><span style="color: red;">*</span>名称：</label>
			<div class="layui-input-inline">
				<input class="layui-input" type="text" name="menuName" id="menuName" placeholder="请输入名称" value="${sysMenu.menuName}"  title="名称"/>
			</div>
		</div>
		<div class="layui-form-item layui-form-item-dialog-menu">
			<label class="layui-form-label">上级：</label>
			<div class="layui-input-inline">
				<input class="layui-input" type="text" readonly name="parentName" id="parentName" placeholder="请选择" value="${sysMenu.parentName}"  title="上级"/>
				<input class="layui-input" type="hidden" name="parentId" id="parentId" placeholder="这里输入名称" value="${sysMenu.parentId}"  title="名称"/>
			</div>
		</div>
		<div class="layui-form-item layui-form-item-dialog-menu">
			<label class="layui-form-label"><span style="color: red;">*</span>权限：</label>
			<div class="layui-input-inline">
				<input class="layui-input" type="text" name="permission" id="permission" placeholder="请输入权限" value="${sysMenu.permission}"  title="权限"/>
			</div>
		</div>

		<div class="layui-form-item layui-form-item-dialog-menu">
			<label class="layui-form-label">url：</label>
			<div class="layui-input-inline">
				<input class="layui-input" type="text" name="menuUrl" id="menuUrl" placeholder="请输入URL" value="${sysMenu.menuUrl}"  title="url"/>
			</div>
		</div>
		<div class="layui-form-item layui-form-item-dialog-menu">
			<label class="layui-form-label">层级：</label>
			<div class="layui-input-inline">
				<input class="layui-input" readonly type="text" name="leveled" id="leveled" placeholder="请输入层级" value="${sysMenu.leveled}"  title="层级"/>
			</div>
		</div>
		<div class="layui-form-item layui-form-item-dialog-menu">
			<label class="layui-form-label">类型：</label>
			<div class="layui-input-inline">
				<select id="menuType" name="menuType" lay-filter="menuType">
					<option value="">请选择</option>
					<option value="URL">URL</option>
					<option value="BUTTON">BUTTON</option>
				</select>
			</div>
		</div>
		<div class="layui-form-item layui-form-item-dialog-menu">
			<label class="layui-form-label">备注：</label>
			<div class="layui-input-inline">
				<input class="layui-input" type="text" name="remarks" id="remarks" placeholder="请输入备注" value="${sysMenu.remarks}"  title="备注"/>
			</div>
		</div>
			</div>
	</form>
	<script type="text/javascript">
        var zTree;
		var $form;
		var form;
		layui.use(['form'], function () {
			form = layui.form();
			$form = $('form');
			$("#menuType  option").each(function(){
				if($(this).val() == "${sysMenu.menuType}") {
					$(this).attr("selected",true)
				}
			});
			form.render();

            var zn = '${zTreeNodes}';
            zn=zn.replace(/&quot;/g,'"');//转换后台返回的&quot;
            var setting = {
                data: {
                    key: {
                        title: "dept"
                    },
                    simpleData: {
                        enable: true,
                        idKey: "id",
                        pIdKey: "pId",
                        rootPId: 0
                    }
                },
                callback:{
                    onClick: zTreeOnClick
                }
            };
            var zNodes = eval(zn);
            zTree = $.fn.zTree.init($("#tree"), setting, zNodes);
		});

		$(document).ready(function(){

		});
		function zTreeOnClick(event, treeId, treeNode) {
			$("#parentId").val(treeNode.id);
			$("#parentName").val(treeNode.name);
			$("#leveled").val(treeNode.level+1);
		};
		//保存
		function save(){
			if(checkIsNull("menuName","名称不能为空") || checkIsNull("permission","权限不能为空")){
				return false;
			}
			$.ajax({ url: "${basePath}sysuser/menu/saveUpdateSysMenu",
				data: $("#form1").serialize(),
				type: "POST",
				success: function(data){
					if (data.status == 'success') {
						parent.layer.alert(data.msg,function(index){
							var index1 = parent.layer.getFrameIndex(window.name); //获取窗口索引
							parent.layer.close(index1);
							parent.layer.close(index);
						});
					}else{
						parent.layer.alert(data.msg);
					}
				}
			})
		}
	</script>
</body>
</html>


